package com.ars.common.servlet.admin;

import com.ars.common.beans.User.User;
import com.ars.common.dao.UserInfo.getClassUserInfo;
import com.ars.common.dao.permission.CurrentClassPermissionSet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;
import java.util.ArrayList;

/**
 * ClassName: CurrentClassPermissionSettingsServlet
 * Package: com.ars.common.dao.permission
 * Description:
 *
 * @Author: Bryan Long
 * @Create: 2024/7/26 - 15:23
 * @Version: v1.0
 */

@WebServlet("/CurrentClassPermissionSettingsServlet")
public class CurrentClassPermissionSettingsServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response); // 复用处理逻辑
    }
    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        User user = (User) request.getSession().getAttribute("LogUser");
        String userID = user.getUserID();
        String classID = userID.substring(0, 11);


        System.out.println(classID);

        ArrayList<User> userList = new ArrayList<User>();

        try {
            userList = CurrentClassPermissionSet.getUser(classID);
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

        request.setAttribute("userInfo", userList);
        request.getRequestDispatcher("/admin/userPermissionSettings.jsp").forward(request, response);

    }
}
